package com.it.tydic.estate.common.util;

import com.it.tydic.estate.common.constants.Constants;
import com.it.tydic.estate.module.model.inner.TbUser;
import com.it.tydic.estate.module.service.RedisCacheService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Component
public class CurrentUtil {

    public static TbUser getUser(){
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        TbUser user = (TbUser)request.getSession().getAttribute(Constants.CURRENTUSER);
        return user;
    }
    public static String getCurrentUserId(){

        TbUser tbUser= getUser();
        if(tbUser != null){
            return tbUser.getUserId();
        }
        return "0";
    }
}
